#!/usr/bin/env python
#coding:utf-8
from min_p import *
reload(sys)
sys.setdefaultencoding("utf-8")
from selenium import webdriver  
from selenium.webdriver.common.keys import Keys

class TAOBAO_UP_DOWN():
    def __init__():
        chromedriver = "chromedriver.exe"
        self.driver = webdriver.Chrome(executable_path=chromedriver)
        self.driver.set_window_size(1280,800)
    def get_down_page(self):
        self.driver.get('https://sell.taobao.com/auction/merchandise/auction_list.htm&type=1')

    def get_up_page(self):
        self.driver.get('https://sell.taobao.com/auction/merchandise/auction_list.htm')
        
    #检查登录状态（登录时用）
    def check_login(self):
        if "https://sell.taobao.com/auction/merchandise/auction_list.htm" in self.driver.current_url[0:60]:
            print u"-->登录成功"
            return True
        else:
            return False    

    #检查元素是否存在
    def isElementExist(self,element):
        try:
            self.driver.find_element_by_xpath(element)
            return True
        except Exception, e:
            return False


    #下架操作
    def down(self,code):
        self.driver.find_element_by_xpath('//*[@id="outer-id"]').clear()
        self.driver.find_element_by_xpath('//*[@id="outer-id"]').send_keys('1045418')#查找
        self.driver.find_element_by_xpath('//*[@id="outer-id"]').send_keys(Keys.ENTER)
        if self.isElementExist('//*[@id="J_DataTable"]/div[2]/table/thead/tr[2]/td/div/input[2]'):
            self.driver.find_element_by_xpath('//*[@id="J_DataTable"]/div[2]/table/thead/tr[2]/td/div/input[2]').click()
            self.driver.find_element_by_xpath('//*[@id="J_DataTable"]/div[2]/table/thead/tr[2]/td/div/button[1]').click()

    #检查下架状态
    def check_down_state(self):
        return self.isElementExist('//*[@id="main-content"]/div[2]/div[2]')

    def up(self,code):
        pass





